from Inspect import app
from datetime import datetime
import time
from flask import request, jsonify, render_template
from Inspect.countroller.userCountroller import userController
from Inspect.countroller.departmentCountroller import departmentCountroller
from Inspect.countroller.equipmentsCountroller import equipmentsCountroller


@app.route('/login', methods=["get"])
def index():
    phone = request.args.get("phone")
    password = request.args.get("password")
    obj = userController.login(phone=phone, password=password)
    return obj


@app.route('/register', methods=["get"])
def register():
    name = request.args.get("name")
    phone = request.args.get("phone")
    password = request.args.get("password")
    department = request.args.get("department")
    position = request.args.get("position")
    jurisdiction = request.args.get("jurisdiction")
    portrait = request.args.get("portrait")
    code = request.args.get("code")
    obj = userController.register(name=name, phone=phone, password=password, department=department, position=position,jurisdiction=jurisdiction, portrait=portrait, code=code)
    return obj


@app.route('/getUserList', methods=["get"])
def list():
    list = userController.getList()
    return {
        "code": "200",
        "data": list
    }

# 添加部门
@app.route('/addDepartment')
def addDepartment():
    departmentName=request.args.get("departmentName")
    obj = departmentCountroller.addDepartment(departmentName=departmentName)
    return obj

# 获取部门列表
@app.route('/getDepartmentList')
def getDepartmentList():
    print(datetime.now())
    obj = departmentCountroller.getDepartmentList()
    return {"code":"200","data":obj}
